//
//  BIDCategoryForExchangeListViewController.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/13.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDCategoryForExchangeListViewController.h"

@interface BIDCategoryForExchangeListViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation BIDCategoryForExchangeListViewController
@synthesize dataSourceArr;
@synthesize delegate;
@synthesize selectedCategoryID;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"类目";
    self.tableView.tableFooterView = [[UIView alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSourceArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    static NSString *identifier = @"identifier";
    NSUInteger row = indexPath.row;
    cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    NSDictionary *dic = self.dataSourceArr[row];
    cell.textLabel.text = dic[@"name"];
    if(selectedCategoryID.length > 0)
    {
        if([selectedCategoryID isEqualToString:dic[@"id"]])
        {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        else
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSUInteger row = indexPath.row;
    NSDictionary *dic = dataSourceArr[row];
    [delegate getCategoryName:dic[@"name"] andID:dic[@"id"]];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
